from PIL import Image

from xml.dom.minidom import parse

def getTagContentList(xmlFile, tagName):
    a = parse(xmlFile)
    l = a.getElementsByTagName(tagName)
    return l
    
def hui(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            a = (r+g+b)/3
            pixels[i,j] = (int(a),int(a),int(a))
    img.save(k, "PNG")
    
def blue(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            a = (r+g+b)/3
            pixels[i,j] = (0,0,b)
    img.save(k, "PNG")
    
def red(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            a = (r+g+b)//3
            pixels[i,j] = (r,0,0)
    img.save(k, "PNG")
    
def green(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            a = (r+g+b)//3
            pixels[i,j] = (0,0,g)
    img.save(k, "PNG")
    

def liang(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            pixels[i,j] = (int(r*1.1),int(g*1.1),int(b*1.1))
    img.save(k, "PNG")
    
def an(j,k):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            pixels[i,j] = (int(r*0.9),int(g*0.9),int(b*0.9))
    img.save(k, "PNG")
    
def bfhui(j,k,l):
    img = Image.open(j);
    pixels = img.load()
    x,y=img.size
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            a = (r+g+b)/3
            if (r > a * l) :
                pixels[i,j] = (int(a),int(a),int(a))
    img.save(k, "PNG")
    
def lan(q,w,e,k):
    img = Image.open(q);
    pixels = img.load()
    lea = Image.open(w);
    p = lea.load()
    x,y=img.size
    
    for i in range(x):
        for j in range(y):
            (r,g,b)=pixels[i,j]
            (l,m,n)=p[i,j]
            a = (r+g+b)/3
            if (r > a * k) :
                pixels[i,j] = (l,m,n)
    img.save(e, "PNG")
    
    


